<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.pyb.model.Student" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>编辑学生信息</title>
    <!-- 引入 Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .form-container {
            max-width: 500px;
            margin: 80px auto;
            padding: 30px;
            background-color: white;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h2 {
            margin-bottom: 25px;
        }
        .form-label {
            font-weight: 500;
        }
        .btn-back {
            display: inline-block;
            margin-top: 15px;
        }
    </style>
</head>
<body>

<!-- 导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">学生信息管理系统</a>
    </div>
</nav>

<div class="container">
    <div class="form-container">
        <h2 class="text-center">编辑学生信息</h2>

        <%
            Student student = (Student) request.getAttribute("student");
            if (student == null) {
        %>
        <div class="alert alert-danger text-center" role="alert">
            学生信息不存在，请返回查看。
        </div>
        <div class="text-center">
            <a href="student?action=list" class="btn btn-outline-secondary btn-sm">&laquo; 返回列表</a>
        </div>
        <%
        } else {
        %>
        <form action="student" method="post">
            <!-- 隐藏字段 -->
            <input type="hidden" name="action" value="update"/>
            <input type="hidden" name="id" value="<%= student.getId() %>"/>

            <div class="mb-3">
                <label for="name" class="form-label">姓名</label>
                <input type="text" class="form-control" id="name" name="name"
                       value="<%= student.getName() %>" required>
            </div>

            <div class="mb-3">
                <label for="age" class="form-label">年龄</label>
                <input type="number" class="form-control" id="age" name="age"
                       value="<%= student.getAge() %>" min="0" required>
            </div>

            <div class="d-grid gap-2">
                <button type="submit" class="btn btn-primary">更新学生信息</button>
            </div>
        </form>

        <div class="text-center mt-3">
            <a href="student?action=list" class="btn btn-outline-secondary btn-sm btn-back">&laquo; 返回学生列表</a>
        </div>
        <%
            }
        %>
    </div>
</div>
<!-- 引入 Bootstrap JS Bundle（包含 Popper） -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>